package main

import "strings"

func main() {

	//strsArray := []string{"a", "b", "c"}

	//测试用例
	//nums := 1234
	str := "()[]{}"

	//打印测试用例返回结果
	resp := isValid(str)
	println(resp)

}

func isValid(str string) bool {
	s := strings.Split(str, "")
	strLen := len(s)
	//添加键值对  键为左字符  值为右字符
	mapType := make(map[string]string)
	mapType["("] = ")"
	mapType["["] = "]"
	mapType["{"] = "}"

	seqArr := []string{}
	for i := 0; i < strLen; i++ {

		if s[i] == ")" || s[i] == "]" || s[i] == "}" {
			seqArrLen := len(seqArr)
			if seqArrLen == 0 { //已经没有供其消去的顺序数组元素了
				return false
			}
			if mapType[seqArr[seqArrLen-1]] == s[i] { //key对应的value成立
				seqArr = seqArr[:seqArrLen-1] //将最后一个元素弹出来
			} else {
				return false
			}
			/* for j := seqArrLen; j >= 0; j-- { //倒序遍历顺序数组元素
				if condition {
					seqArr.pop
				}
			} */
		} else {
			seqArr = append(seqArr, s[i]) //添加数组元素到顺序数组
		}
	}
	if len(seqArr) == 0 {
		return true
	}
	return false

}
